import * as actionTypes from "../actions/action-types"

const initTodo = {
    count : 1,
    data : [{
        id : 0,
        text : "来一个列表"
    }]
}

export default function todo(state = initTodo, action){
    switch(action.type){
        case actionTypes.ADD_TODO:{
            let s = Object.assign({}, state);
            s.data = [
                ...s.data,
                {
                    id : s.count,
                    text  : action.text
                }
            ];
            s.count ++;
            return s;
            break
        }
        case actionTypes.DEL_TODO:{
            let s = Object.assign({}, state);
            delete s.data[action.id];
            return s;
            break
        }
        default:
            return state;
    }

}